And Çetin
You should be petrified when copy-pasting code

You should be petrified when copy-pasting code

Almost no developer writes code from scratch. Depending on his experience, he has probably already written a project similar to the one he's working on, and all he has to do is to make the necessary changes based on that previous code.

This logic also applies within the same project: Once the foundation is established, each function is somewhat like an evolution of the previous ones.

If you have to build a brand new block of code that you've never written before, you won't be bothered by it; because you know that when the next projects need the same function, this experience will relieve your hands greatly.


What if I use someone else's code?


There are cases where copy-pasting is almost inevitable. However, these are also the cases that will give you the most headache afterwards.

Let's say your app will use a payment infrastructure like Stripe. This is a very complex API (application programming interface) and there is almost nowhere you can step in during the transmission and processing of customers' payment information — you have to use their code as it is. The only thing you can customize is probably the design of the checkout page.

For a teacher, it is easy to solve a problem and explain how it is solved. What's difficult is to find the error in the student's solution.

The problem is that with very extensive copy-pasted code like this, when something goes wrong, or if you want to change any detail, you will have to read and understand what's going on with all those variables and classes and functions. And believe me, the effort you put in in the meantime will wipe out the time you saved while copying and pasting.

The same logic applies to plugins/packages. Let's assume you want to add some complex functionality to your application. You googled it and a highly up-voted one-line comment on Stackoverflow suggested you a package that does exactly what you want, by sharing its GitHub repository; all you have to do is add it to your project and apply it swiftly by following the instructions.

The next comment just below showed you roughly how you can achieve what you want with a snippet including dozens of lines of code. But you need to work on it a lot to make it do what you want.

Which one should you choose?

The first option is a Pyrrhic victory; You will reach your destination by cutting corners, but you will not gain any experience.

Plus, as we mentioned above, the package that does what you want with just a few lines of code actually pulls the strings of hundreds of additional lines in the background; and let's pray to God that it does exactly what you want it to do and the author keeps the package up to date/continues to support it, because it can cost you precious days to modify or debug it if there is any problem in the future.

Okay; in the second option, you will also begin by copying another user's code. But at least you will have to understand how it works — even if you do not want to — while making the necessary changes on it. More importantly, you will see how it works.


CTRL + C is a time bomb


...and will fire the moment you CTRL + P. In order to survive with minimum damage, as we said in our previous article...< /p>

Do this as little as possible and try to understand, absorb, digest every line of code you 'carry'.

0 Comments

Leave a Comment